package com.example.hanjyLearn.core;

/**
 * 统一的返回数据结构
 * @param <T>
 */
public class Result<T> {

    private String code;

    private String msg;

    private T data;

    private int total;

    public static <T> Result<T> success(T data) {
        return new Result<T>()
                .setCode("200")
                .setData(data)
                .setMsg("操作成功");
    }

    public static <T> Result<T> failed(String msg) {
        return new Result<T>()
                .setCode("500")
                .setMsg(msg);
    }

    public static Result<Void> success() {
        return success(null);
    }

    public String getCode() {
        return code;
    }

    public Result<T> setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public int getTotal() {
        return total;
    }

    public Result<T> setTotal(int total) {
        this.total = total;
        return this;
    }
}
